# 定义客户端行为，点击右边条目，可自动插入功能代码
# 定义客户端行为，点击右边条目，可自动插入功能代码

# 导入HAR文件中的http请求 
# 自己检查，去除不必要的请求

from urllib.parse import quote
from base64 import  b64encode
from random import randint
import json
import time

# 创建客户端     
client = HttpClient('127.0.0.1', # 目标地址:端口
                    timeout=10   # 超时时间，单位秒
                   ) 

response = client.sendAndRecv(
'GET',
  'http://127.0.0.1/distributor/sign.html',
  headers={
    'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
    'Accept-Encoding':'gzip, deflate, br',
    'Accept-Language':'zh-CN,zh;q=0.9',
    'Cache-Control':'max-age=0',
    'Connection':'keep-alive',
    'Host':'127.0.0.1',
    'If-Modified-Since':'Sat, 18 Apr 2020 13:08:52 GMT',
    'Sec-Fetch-Dest':'document',
    'Sec-Fetch-Mode':'navigate',
    'Sec-Fetch-Site':'none',
    'Sec-Fetch-User':'?1',
    'Upgrade-Insecure-Requests':'1',
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36',
    'sec-ch-ua':'".Not/A)Brand";v="99", "Google Chrome";v="103", "Chromium";v="103"',
    'sec-ch-ua-mobile':'?0',
    'sec-ch-ua-platform':'"Windows"'
  },

  
)


username = f'sell_{arg}'
password = '88888888'
up = b64encode(quote(username+'#$%'+password).encode())
    
response = client.post(
    '/api/distributor/signin',
    # 通过data传入指定urlencode格式的消息体参数
    data={'up':up})


# 获取消息头Content-Type值
jwt = response.headers['jwt']    
# print(f"消息头jwt值为 {jwt} ") 




# 请求 9
response = client.sendAndRecv(
'GET',
  'http://127.0.0.1/api/distributor/orders?action=list&pagenum=1&pagesize=5&keywords=&_=1660776285089',
 headers={
    'Accept':'*/*',
    'Accept-Encoding':'gzip, deflate, br',
    'Accept-Language':'zh-CN,zh;q=0.9',
    'Authorization':jwt,
    'Connection':'keep-alive',
    'Content-Type':'application/x-www-form-urlencoded',
    'Host':'127.0.0.1',
    'Referer':'http://127.0.0.1/distributor/index.html',
    'Sec-Fetch-Dest':'empty',
    'Sec-Fetch-Mode':'cors',
    'Sec-Fetch-Site':'same-origin',
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36',
    'X-Requested-With':'XMLHttpRequest',
    'sec-ch-ua':'".Not/A)Brand";v="99", "Google Chrome";v="103", "Chromium";v="103"',
    'sec-ch-ua-mobile':'?0',
    'sec-ch-ua-platform':'"Windows"'
  },

  
)


for j in range(2):
    for i in [2,3,4,5,4,3,2,1]:
        print(f'sell_{arg}准备查看第{i}页')
        response = client.sendAndRecv(
        'GET',
        f'http://127.0.0.1/api/distributor/orders?action=list&pagenum={i}&pagesize=5&keywords=&_=1660796525449',
          headers={
            'Accept':'*/*',
            'Accept-Encoding':'gzip, deflate, br',
            'Accept-Language':'zh-CN,zh;q=0.9',
            'Authorization':jwt,
            'Connection':'keep-alive',
            'Content-Type':'application/x-www-form-urlencoded',
            'Host':'127.0.0.1',
            'Referer':'http://127.0.0.1/distributor/index.html',
            'Sec-Fetch-Dest':'empty',
            'Sec-Fetch-Mode':'cors',
            'Sec-Fetch-Site':'same-origin',
            'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36',
            'X-Requested-With':'XMLHttpRequest',
            'sec-ch-ua':'".Not/A)Brand";v="99", "Google Chrome";v="103", "Chromium";v="103"',
            'sec-ch-ua-mobile':'?0',
            'sec-ch-ua-platform':'"Windows"'
          },
        )
        print(f'sell_{arg}正在查看第{i}页')
        
        
        time.sleep(30)



# for i in [5]:
#     print(f'sell_{arg}准备查看第{i}页')
#     response = client.sendAndRecv(
#     'GET',
#     f'http://127.0.0.1/api/distributor/orders?action=list&pagenum={i}&pagesize=5&keywords=&_=1660796525449',
#       headers={
#         'Accept':'*/*',
#         'Accept-Encoding':'gzip, deflate, br',
#         'Accept-Language':'zh-CN,zh;q=0.9',
#         'Authorization':jwt,
#         'Connection':'keep-alive',
#         'Content-Type':'application/x-www-form-urlencoded',
#         'Host':'127.0.0.1',
#         'Referer':'http://127.0.0.1/distributor/index.html',
#         'Sec-Fetch-Dest':'empty',
#         'Sec-Fetch-Mode':'cors',
#         'Sec-Fetch-Site':'same-origin',
#         'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36',
#         'X-Requested-With':'XMLHttpRequest',
#         'sec-ch-ua':'".Not/A)Brand";v="99", "Google Chrome";v="103", "Chromium";v="103"',
#         'sec-ch-ua-mobile':'?0',
#         'sec-ch-ua-platform':'"Windows"'
#       },
#     )
#     print(f'sell_{arg}正在查看第{i}页')
    
    
#     time.sleep(1)
    
 
    
